package top.hidoctor.auscultation.widget;

import android.graphics.Bitmap;
import android.util.Log;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.request.target.ImageViewTarget;

/**
 * 版    本：1.0
 * 描    述：设置图片等比缩放
 * <p>glide处理图片.</p>
 */
public class TransformationUtils extends ImageViewTarget<Bitmap> {

    private ImageView target;

    public TransformationUtils(ImageView target) {
        super(target);
        this.target = target;
    }

    @Override
    protected void setResource(Bitmap resource) {
        view.setImageBitmap(resource);
        //获取原图的宽高
        int width = resource.getWidth();
        int height = resource.getHeight();
        Log.e("TAG", "setResource: " + width);
        Log.e("TAG", "setResource: " + height);

        //获取imageView的宽
        int imageViewWidth = target.getWidth();
        target.setScaleType(ImageView.ScaleType.FIT_XY);
//        //计算缩放比例
//        float sy = (float) (imageViewWidth * 0.1) / (float) (width * 0.1);
//
//        //计算图片等比例放大后的高
//        int imageViewHeight = (int) (height * sy);
        ViewGroup.LayoutParams params = target.getLayoutParams();
        params.height = height;
        params.width = width;
        target.setLayoutParams(params);
    }
}